#binDir=$(wildcard bin)
#targetDir=$(wildcard target)
confName="conf/config.yaml"
ifneq ($(profile),)
	confName="conf/config.$(profile).yaml"
endif

define createDir
	@ \
	if [ ! -d target ]; then \
		mkdir target; \
	fi; \
	if [ ! -d bin ]; then \
		mkdir bin; \
	fi;
endef

define package
	@ \
	echo "$(confName)"; \
	confName="conf/config.yaml"; \
	if [ -n "$(profile)" ];then \
		confName="conf/config.$(profile).yaml"; \
	fi;	\
	if [[ ! -f $$confName ]];then \
		echo "no conf file"; \
		exit 1; \
	fi;	\
	if [ ! -d target/zCron/conf ]; then \
		mkdir -p target/zCron/conf; \
	fi; \
	if [ ! -d target/zCron/bin ]; then \
		mkdir -p target/zCron/bin; \
	fi; \
	cp bin/* "target/zCron/bin/"; \
	cp $$confName target/zCron/conf/config.yaml; \
	cd target; \
	tar zcvf ${1}.tar.gz zCron; \
	rm -rf zCron; \
	cd ..;
endef

define aaa

endef

dir:
	$(call createDir,)


.PHONY: clean
clean:
	rm -rf bin target

build-linux-64: dir
	GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o bin/zcron-linux-64 cmd/task.go
	$(call package,"linux", "zcron")

build-linux-32: dir
	GOOS=linux GOARCH=386 go build -ldflags="-w -s" -o bin/zcron-linux-32 cmd/task.go
	$(call package,"linux", "zcron")

build-darwin-64: dir
	GOOS=darwin GOARCH=amd64 go build -ldflags="-w -s" -o bin/zcron-darwin-64 cmd/task.go
	#$(call package,"darwin", "zcron")
#ifneq ("window" , "windows")
#	@echo "same != diff"
#else
#	@echo "same == diff"
#endif
build-windows-64: dir
	GOOS=windows GOARCH=amd64 go build -ldflags="-w -s" -o bin/zcron-windows-64.exe cmd/task.go
	$(call package,"windows", "zcron.exe")
build-windows-32: dir
	GOOS=windows GOARCH=386 go build -ldflags="-w -s" -o bin/zcron-windows-32.exe cmd/task.go
	$(call package,"windows", "zcron.exe")

build: build-linux-64 build-linux-32 build-darwin-64 build-windows-64 build-windows-32


